<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>  
<%@ taglib prefix="ujn" uri="http://ujn.edu.cn/common/"%> 
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() 
	                   + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML> 
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>项目管理</title>
	<!-- 引入css样式文件 -->
	<!-- Bootstrap Core CSS -->
	<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
	<!-- MetisMenu CSS -->
	<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
	<!-- DataTables CSS -->
	<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
	<!-- Custom CSS -->
	<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
	<!-- Custom Fonts -->
	<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
  <!-- 导航栏部分 -->
  <nav class="navbar navbar-default navbar-static-top" role="navigation"
		 style="margin-bottom: 0">
	<div class="navbar-header">
		<a class="navbar-brand" href="<%=basePath%>customer/list.action">客户管理系统</a>
	</div>
	<!-- 导航栏右侧图标部分 -->
	<ul class="nav navbar-top-links navbar-right">
	    <!-- 邮件通知 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 邮件通知
			</a>
			<ul class="dropdown-menu dropdown-messages">
				<li>
				    <a href="#">
						<div>
							<strong>张经理</strong> <span class="pull-right text-muted">
								<em>昨天</em>
							</span>
						</div>
						<div>今天晚上开会，讨论一下下个月工作的事...</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a class="text-center" href="#">
				        <strong>查看全部消息</strong>
						
				    </a>
				</li>
			</ul>
		</li>
		<!-- 邮件通知 end -->
		<!-- 任务通知 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 任务通知
			</a>
			<ul class="dropdown-menu dropdown-tasks">
				<li>
				    <a href="#">
						<div>
							<p>
								<strong>任务 1</strong> 
								<span class="pull-right text-muted">完成40%</span>
							</p>
							<div class="progress progress-striped active">
								<div class="progress-bar progress-bar-success"
									role="progressbar" aria-valuenow="40" aria-valuemin="0"
									aria-valuemax="100" style="width: 40%">
									<span class="sr-only">完成40%</span>
								</div>
							</div>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a href="#">
						<div>
							<p>
								<strong>任务 2</strong> 
								<span class="pull-right text-muted">完成20%</span>
							</p>
							<div class="progress progress-striped active">
								<div class="progress-bar progress-bar-info" role="progressbar"
									aria-valuenow="20" aria-valuemin="0" aria-valuemax="100"
									style="width: 20%">
									<span class="sr-only">完成20%</span>
								</div>
							</div>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a class="text-center" href="#"> 
				        <strong>查看所有任务</strong>
				    </a>
				</li>
			</ul> 
		</li>
		<!-- 任务通知 end -->
		<!-- 消息通知 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 消息通知
			</a>
			<ul class="dropdown-menu dropdown-alerts">
				<li>
				    <a href="#">
						<div>
							 新回复 
							<span class="pull-right text-muted small">4分钟之前</span>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a href="#">
						<div>
							新消息 
							<span class="pull-right text-muted small">4分钟之前</span>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a href="#">
						<div>
							 新任务 
							<span class="pull-right text-muted small">4分钟之前</span>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a href="#">
						<div>
							服务器重启 
							<span class="pull-right text-muted small">4分钟之前</span>
						</div>
				    </a>
				</li>
				<li class="divider"></li>
				<li>
				    <a class="text-center" href="#"> 
				        <strong>查看所有提醒</strong>
				    </a>
				</li>
			</ul> 
		</li>
		<!-- 消息通知 end -->
		<!-- 用户信息和系统设置 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 用户信息和系统设置
				
			</a>
			<ul class="dropdown-menu dropdown-user">
				<li><a href="#">
				               用户：${USER_SESSION.user_name}
				    </a>
				</li>
				<li><a href="#">系统设置</a></li>
				<li class="divider"></li>
				<li>
					<a href="${pageContext.request.contextPath }/logout.action">
					退出登录
					</a>
				</li>
			</ul> 
		</li>
		<!-- 用户信息和系统设置结束 -->
	</ul>
	<!-- 左侧显示列表部分 start-->
	<div class="navbar-default sidebar" role="navigation">
		<div class="sidebar-nav navbar-collapse">
			<ul class="nav" id="side-menu">
				<li class="sidebar-search">
					<div class="input-group custom-search-form">
						<input type="text" class="form-control" placeholder="查询内容...">
						<span class="input-group-btn">
							<button class="btn btn-default" type="button">
								查询
							</button>
						</span>
					</div> 
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/customer/list.action" class="active">
				      客户管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/user/list.action" class="active">
				      用户管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/basedict/list.action" class="active">
				      数据字典管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/orders/list.action" class="active">
				      订单管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/product/list.action" class="active">
				      产品管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/project/list.action" class="active">
				      项目管理
				    </a>
				</li>
			</ul>
		</div>
	</div>
	<!-- 左侧显示列表部分 end--> 
  </nav>
  <!-- 项目列表查询部分  start-->
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">项目管理</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->
		<div class="panel panel-default">
			<div class="panel-body">
				<form class="form-inline" method="get" 
				      action="${pageContext.request.contextPath }/project/list.action">
					<div class="form-group">
						<label for="projectid">项目ID</label> 
						<input type="text" class="form-control" id="projectid" 
						                   value="${projectid}" name="project_id" />
					</div>
					<div class="form-group">
						<label for="employeeid">负责员工ID</label> 
						<input type="text" class="form-control" id="employeeid" 
						                   value="${employeeid}" name="employee_id" />
					</div>
					<div class="form-group">
						<label for="projectstate">项目状态</label> 
						<input type="text" class="form-control" id="projectstate" 
						                   value="${projectstate}" name="project_state" />
					</div>
					<button type="submit" class="btn btn-primary">查询</button>
				</form>
			</div>
		</div>
		<a href="#" class="btn btn-primary" data-toggle="modal" 
		           data-target="#newprojectDialog" onclick="clearproject()">新建</a>
		
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">项目信息列表</div>
					<!-- /.panel-heading -->
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>项目ID</th>
								<th>负责员工ID</th>
								<th>项目佣金</th>
								<th>项目版本</th>
								<th>项目状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${page.rows}" var="row">
								<tr>
									<td>${row.project_id}</td>
									<td>${row.employee_id}</td>
									<td>${row.project_commission}</td>
									<td>${row.project_version}</td>
									<td>${row.project_state}</td>
									<td>
									<c:if test="${row.employee_id==USER_SESSION.user_id}">
									<a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#projectEditDialog" onclick= "editProject(${row.project_id})">修改</a>
									<a href="#" class="btn btn-danger btn-xs" onclick="deleteProject(${row.project_id})">删除</a>
									</c:if>
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<div class="col-md-12 text-right">
						<ujn:page url="${pageContext.request.contextPath}/project/list.action" />
					</div>
					<!-- /.panel-body -->
				</div>
				<!-- /.panel -->
			</div>
			<!-- /.col-lg-12 -->
		</div>
	</div>
	<!-- 项目列表查询部分  end-->
</div>
  <!-- 创建用户模态框 -->
<div class="modal fade" id="newprojectDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新建用户信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="new_project_form">
					
					<div class="form-group">
						<label for="new_employeeid" class="col-sm-2 control-label">
						    负责员工
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_employeeid" placeholder="负责员工ID" name="employee_id" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_projectcommission" class="col-sm-2 control-label">
						    项目佣金
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_projectcommission" placeholder="项目佣金" name="project_commission" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_projectversion" class="col-sm-2 control-label">
						    项目版本
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_projectversion" placeholder="项目版本" name="project_version" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_projectstate" class="col-sm-2 control-label">
						    项目状态
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_projectstate" placeholder="项目状态（0完结，1进行中）" name="project_state" />
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="createproject()">创建项目</button>
			</div>
		</div>
	</div>
</div>
<!-- 修改用户项模态框 -->
<div class="modal fade" id="projectEditDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">修改项目信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="edit_project_form">
					
				<div class="form-group">
						<label for="edit_projectId" class="col-sm-2 control-label">项目ID</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_projectId" name="project_id" readonly/>
						</div>
					</div>
					<div class="form-group">
						<label for="edit_employeeId" class="col-sm-2 control-label">负责员工</label> 
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_employeeId" placeholder="请输入负责员工ID" name="employee_id" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_projectCommission" class="col-sm-2 control-label">项目佣金</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_projectCommission" placeholder="请输入项目佣金" name="project_commission" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_projectVersion" class="col-sm-2 control-label">项目版本</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_projectVersion" placeholder="请输入项目版本" name="project_version" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_projectState" class="col-sm-2 control-label">项目状态</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_projectState" placeholder="请输入项目状态（完结0，未完1）" name="project_state" />
						</div>
					</div>
					
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="updateProject()">保存修改</button>
			</div>
		</div>
	</div>
</div>
<!-- 引入js文件 -->
<!-- jQuery -->
<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="<%=basePath%>js/metisMenu.min.js"></script>
<!-- DataTables JavaScript -->
<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="<%=basePath%>js/sb-admin-2.js"></script>
<!-- 编写js代码 -->
<script type="text/javascript">
//清空新建项目窗口中的数据
	function clearproject() {
		$("#new_projectid").val("");
	    $("#new_employeeid").val("");
	    $("#new_projectcommission").val("");
	    $("#new_projectversion").val("");
	    $("#new_projectstate").val("");
	}
	// 创建项目
	function createproject() {
	$.post("<%=basePath%>project/create.action",
	$("#new_project_form").serialize(), function(data){
	        if(data =="OK"){
	            alert("项目创建成功！");
	            window.location.reload();
	        }else if(data == "FAIL1"){
	        	alert("负责员工不存在，项目创建失败！");
	            window.location.reload();
	        }else{
	            alert("项目创建失败！");
	            window.location.reload();
	        }
	    });
	}
	
	// 通过id获取修改的项目信息
	function editProject(id) {
	    $.ajax({
	        type:"get",
	        url:"<%=basePath%>project/getProject.action",
	        data:{"id":id},
	        success:function(data) {
	        	$("#edit_projectId").val(data.project_id);
	            $("#edit_employeeId").val(data.employee_id);
	            $("#edit_projectCommission").val(data.project_commission);
	            $("#edit_projectVersion").val(data.project_version);
	            $("#edit_projectState").val(data.project_state);
	        }
	    });
	}
	    // 执行修改项目操作
	function updateProject() {
		$.post("<%=basePath%>project/update.action",$("#edit_project_form").serialize(),function(data){
			if(data =="OK"){
				alert("项目信息更新成功！");
				window.location.reload();
			}else if(data =="FAIL1"){
				alert("负责员工不存在，项目信息更新失败！");
				window.location.reload();
			}else if(data =="FAIL2"){
				alert("项目信息更新失败！");
				window.location.reload();
			}
		});
	}
	// 删除项目
	function deleteProject(id) {
	    if(confirm('确实要删除该项目吗?')) {
	$.post("<%=basePath%>project/delete.action",{"id":id},
	function(data){
	            if(data =="OK"){
	                alert("项目删除成功！");
	                window.location.reload();
	            }else{
	                alert("项目删除失败！");
	                window.location.reload();
	            }
	        });
	    }
	}
</script>
</body>
</html>